package com.freework.report.xmlreport.define.service;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBException;

import org.springframework.stereotype.Service;

import com.freework.report.base.service.ReportService;
import com.freework.report.util.XMLUtil;
import com.freework.report.xmlreport.define.vo.ObjectFactory;
import com.freework.report.xmlreport.define.vo.ReportInfoVO;
@Service
public class DefineReportServiceImpi  implements DefineReportServiceI{
	public List<ReportInfoVO> getReportInfoList() {

		String path = ReportService.getCfgpath();
		File file = new File(path);
		File[] files = file.listFiles(new FilenameFilter() {

			public boolean accept(File file, String fileName) {
				if (fileName.endsWith(".xml")) {
					return true;
				}
				return false;
			}
		});
		List<ReportInfoVO> list = new ArrayList<ReportInfoVO>(files.length);
		for (File file2 : files) {
			try {
				ReportInfoVO vo=(ReportInfoVO) XMLUtil.xmlToObject(file2, ObjectFactory.class);
				vo.setCode(file2.getName().substring(0, file2.getName().length()-4));
				list.add(vo);
			} catch (JAXBException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

		return list;

	}

}
